package com.cn.xact.ty_treasured_book.ui;

import com.cn.xact.ty_treasured_book.R;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.GridLayout;
import android.support.v7.widget.GridLayout.LayoutParams;
import android.support.v7.widget.GridLayout.Spec;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;

public class ItemView extends Button {

    BadgeView badgeAgent = null;
    Context myContext = null;

    public static final int RED = 0x7fe9473b;
    public static final int BLUE = 0x7f339ff3;
    private static final int MARGIN = 10;

    public ItemView(Context context, CharSequence title, int width, int height, String icon) {
        super(context);
        myContext = context;

        setText(title);
        setTextColor(Color.WHITE);
        setWidth(width);
        setHeight(height);
        setBackgroundColor(BLUE);
        if ((icon != null) && (!icon.equals(""))) {
            setPadding(0, height/4, 0, 0);
            setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(getResources().getIdentifier(icon, "drawable", myContext.getPackageName())), null, null);
        }
    }

    public void setMargin() {
        ((GridLayout.LayoutParams)getLayoutParams()).setMargins(MARGIN, MARGIN, MARGIN, MARGIN);
    }

    public void setImportant() {
        this.setBackgroundColor(RED);
    }

    public BadgeView peekBadgeView() {
        if (badgeAgent == null) {
            badgeAgent = new BadgeView(myContext, this);
        }

        return badgeAgent;
    }
}
